package com.qfedu.edu.utils;

import com.alibaba.fastjson.JSON;
import com.qfedu.edu.result.R;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Slf4j
public class HttpResponseUtils {
    public void sendResponse(R r, HttpServletResponse response) throws IOException {
        PrintWriter writer;
        try {
            //设置响应编码
            response.setContentType("text/html;charset=utf-8");
            writer = response.getWriter();
            writer.write(JSON.toJSONString(r));
        } catch (IOException e) {
            log.info("获取response的writer失败");
        } finally {
//            writer.flush();
//            writer.close();
        }
    }
}
